using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;

namespace JingQiao.Ads.Infrastructure.Data.NH.DomainObject
{
    using Domain.Model.DomainObject;

    public partial class DestPositionAd : IDestPositionAd
    {
        #region Primitive Properties
    
        public virtual int AdvertisementId
        {
            get { return _advertisementId; }
            set
            {
                if (_advertisementId != value)
                {
                    if (Advertisement != null && Advertisement.AdvertisementId != value)
                    {
                        Advertisement = null;
                    }
                    _advertisementId = value;
                }
            }
        }
        private int _advertisementId;
    
        public virtual int PositionId
        {
            get { return _positionId; }
            set
            {
                if (_positionId != value)
                {
                    if (Position != null && Position.PositionId != value)
                    {
                        Position = null;
                    }
                    _positionId = value;
                }
            }
        }
        private int _positionId;
    
        public virtual int DestinationId
        {
            get { return _destinationId; }
            set
            {
                if (_destinationId != value)
                {
                    if (Destination != null && Destination.DestinationId != value)
                    {
                        Destination = null;
                    }
                    _destinationId = value;
                }
            }
        }
        private int _destinationId;
    
        public virtual int Sequence
        {
            get;
            set;
        }
    
        public virtual byte Status
        {
            get;
            set;
        }
    
        public virtual System.DateTime StartDate
        {
            get;
            set;
        }
    
        public virtual System.DateTime ExpireDate
        {
            get;
            set;
        }
    
        public virtual string Creator
        {
            get;
            set;
        }
    
        public virtual System.DateTime CreateDate
        {
            get;
            set;
        }

        #endregion
        #region Navigation Properties
    
        public virtual IAdvertisement Advertisement
        {
            get { return _advertisement; }
            set
            {
                if (!ReferenceEquals(_advertisement, value))
                {
                    var previousValue = _advertisement;
                    _advertisement = value;
                    FixupAdvertisement(previousValue);
                }
            }
        }
        private IAdvertisement _advertisement;
    
        public virtual IDestination Destination
        {
            get { return _destination; }
            set
            {
                if (!ReferenceEquals(_destination, value))
                {
                    var previousValue = _destination;
                    _destination = value;
                    FixupDestination(previousValue);
                }
            }
        }
        private IDestination _destination;
    
        public virtual IPosition Position
        {
            get { return _position; }
            set
            {
                if (!ReferenceEquals(_position, value))
                {
                    var previousValue = _position;
                    _position = value;
                    FixupPosition(previousValue);
                }
            }
        }
        private IPosition _position;

        #endregion
        #region Association Fixup
    
        private void FixupAdvertisement(IAdvertisement previousValue)
        {
            if (previousValue != null && previousValue.DestPositionAd.Contains(this))
            {
                previousValue.DestPositionAd.Remove(this);
            }
    
            if (Advertisement != null)
            {
                if (!Advertisement.DestPositionAd.Contains(this))
                {
                    Advertisement.DestPositionAd.Add(this);
                }
                if (AdvertisementId != Advertisement.AdvertisementId)
                {
                    AdvertisementId = Advertisement.AdvertisementId;
                }
            }
        }
    
        private void FixupDestination(IDestination previousValue)
        {
            if (previousValue != null && previousValue.DestPositionAd.Contains(this))
            {
                previousValue.DestPositionAd.Remove(this);
            }
    
            if (Destination != null)
            {
                if (!Destination.DestPositionAd.Contains(this))
                {
                    Destination.DestPositionAd.Add(this);
                }
                if (DestinationId != Destination.DestinationId)
                {
                    DestinationId = Destination.DestinationId;
                }
            }
        }
    
        private void FixupPosition(IPosition previousValue)
        {
            if (previousValue != null && previousValue.DestPositionAd.Contains(this))
            {
                previousValue.DestPositionAd.Remove(this);
            }
    
            if (Position != null)
            {
                if (!Position.DestPositionAd.Contains(this))
                {
                    Position.DestPositionAd.Add(this);
                }
                if (PositionId != Position.PositionId)
                {
                    PositionId = Position.PositionId;
                }
            }
        }

        #endregion
    }
}
